# -*- coding: utf-8 -*- 
"""
========================================================================================================================
@project : modelscope-sanic
@file: ocr-recognition_handwriting
@Author: mengying
@email: 652044581@qq.com
@date: 2023/3/9 9:30
@desc: OFA文字识别-中文-手写体-base
========================================================================================================================
"""
class SingletonDecorator:
    def __init__(self, cls):
        self.cls = cls
        self._instance = None

    def __call__(self, *args, **kwargs):
        if self._instance is None:
            self._instance = self.cls(*args, **kwargs)
        return self._instance


@SingletonDecorator
class HandwritingOcr:

    def __init__(self) -> None:
        from modelscope.pipelines import pipeline
        from modelscope.utils.constant import Tasks
        self.model = pipeline(Tasks.ocr_recognition, model='damo/cv_convnextTiny_ocr-recognition-handwritten_damo')
        print("handwriting_ocr loaded successfully")
